/* 
vuex最核心管理对象/仓库 store
*/
import Vue from 'vue'
import Vuex from 'vuex'
import counter from './modules/counter'
import other from './modules/other'
import userSearch from './modules/user-search'
import createPersistedState from "vuex-persistedstate";

// 安装Vuex
Vue.use(Vuex)


// 创建并暴露store
const store = new Vuex.Store({
  modules: {
    counter,
    other,
    userSearch
  },
  // 配置vuex的插件 默认是存储总state
  
  // plugins: [createPersistedState()]   // 如果只想存储某个vuex模块的状态
  plugins: [createPersistedState({  // 指定只存储counter模块的state
    paths: ['counter']
  })]  
})

/* 
总结state的结构: 
{
  counter: {  // 模块的状态对象在总状态的标识名称是模块名
    count: 1
  },
  other: {
    xxx: 2,
    yyy: []
  },
  userSearch: {
    firstView: true,
    loading: false,
    users: [],
    errorMsg: ''
  }
}
*/

export default store
